import plistlib
import os
import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parent.parent))
from Utils.tool import Tool as tool
import serial

class VarStationConfig():

    def __init__(self):
        
        self.urlArr = []
        self.dutArr = []

        plistPath = "{}/Config/VaStationConfig.plist".format(tool().getProjectPath())
        print("VaStationConfig plistPath---",plistPath)
        with open(plistPath,'rb') as fp:
            dict = plistlib.load(fp)
            try:
                self.groups = dict["groups"]
                for i in self.groups:
                    # print("i----",i)
                    dutCon = i["DUT_UART"]
                    url = dutCon["url"]
                    print("url----",url)
                    self.urlArr.append(url)

                    print("self.urlArr-----",self.urlArr)
                    
                    DUT = serial.Serial()
                    DUT.port = url
                    print("port url : ",DUT.port)
                    # DUT.port = '/dev/cu.usbmodem14131202'
                    # '/dev/cu.usbmodem1424202'
                    DUT.baudrate = 115200
                    DUT.timeout = 5
                    DUT.bytesize = 8
                    DUT.stopbits = 1
                    DUT.parity = "N"
                    self.dutArr.append(DUT)

            except Exception as e:
                print("Va Station Config error:",e)
    
if __name__ == '__main__':
    VarStationConfig()
    